//struct SubtitleEntry
function SubtitleEntry(startTime, endTime, subtitleString) {
    this.startTime = startTime;
    this.endTime = endTime;
    this.subtitleString = subtitleString;
}

function SubtitleDecoder() {
    this.subtitleArray = new Array();
}

SubtitleDecoder.prototype.trimString = function (string) {
    return string.replace(/(^\s*)|(\s*$)/g, "");
};

//input 00:01:10 return 110
SubtitleDecoder.prototype.getSecondFromTimeString = function (string) {
    var tmpTime = "";
    var time = string.split(':');
	var hour = parseInt(time[0]);
    var minute = parseInt(time[1]);
    var second = parseInt(time[2]);
	//jso.logd("time",hour+":"+minute+":"+second);
    return (hour * 3600 + minute * 60 + second);
};

//for SubtitleBar input-time(int)
SubtitleDecoder.prototype.getSubtitleContent = function (time) {
    var low, high, mid;
    low = 0;
    high = this.subtitleArray.length - 1;
    while (low <= high) {
        //how to make sure mid is int type
        mid = parseInt((low + high) / 2);
        if (this.subtitleArray[mid].startTime <= time) {
            if (this.subtitleArray[mid].endTime >= time)
                return mid;
            low = mid + 1;
        }
            //subtitleArry[mid].startTime>time
        else {
            high = mid - 1;
        }
    }
    return -1;
};
//SubtitleDecoder.prototype.readSubtitleFile = function () {

//}
//SubtitleDecoder.prototype.printSubtitleArray = function () {
//    for (index in this.subtitleArray) {
//        document.write("SubtitleEntry[" + index + "]<br>");
//        document.write("&nbsp;&nbsp;&nbsp;startTime:" + this.subtitleArray[index].startTime + "<br>");
//        document.write("&nbsp;&nbsp;&nbsp;endTime  :" + this.subtitleArray[index].endTime + "<br>");
//        document.write("&nbsp;&nbsp;&nbsp;content  :" + this.subtitleArray[index].subtitleString + "<br>");
//    }
//}
//SubtitleDecoder.prototype.printSubtitleContent = function (time) {
//    //用于测试getSubtitleEntry(time)
//    document.write("searching:<br>");
//    var index = this.getSubtitleContent(time);
//    document.write("&nbsp;&nbsp;&nbsp;startTime:" + this.subtitleArray[index].subtitleString + "<br>");
//}
